<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/layui/layui.js"></script>
    <script src="/static/js/jquery.min.js"></script>
    <!-- 注意， 只需要引用 JS，无需引用任何 CSS ！！！-->
    <script type="text/javascript" src="/static/wangEditor/wangEditor.min.js"></script>

</head>
<body>
    <%--第一个--%>
    <div id="editor" class="text"></div>

    <input type="button" id="btn" value="提交"/>
</body>

<script type="text/javascript">
    var E = window.wangEditor;
    var editor = new E('#editor');
    // 将图片大小限制为 3M
    editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
    // 限制一次最多上传 5 张图片
    editor.customConfig.uploadImgMaxLength = 5;

    //自己定义上传的方法
    editor.customConfig.customUploadImg = function (files, insert) {
        var daw = new FormData();
        for(var i=0;i<files.length;i++){
            daw.append("files",files[i]);
        }
        $.ajax({
            url:'/uploadFiles/wangEditUploadImage',
            type: "POST",
            data: daw,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success:function(da){
                if(da.errno == 0){
                    for(var j=0;j<da.data.length;j++){
                        insert(da.data[j]);
                    }
                }else{
                    alert(da.msg);
                    return;
                }
            }
        });
    }


    editor.create();

    // 禁用编辑功能
    // editor.$textElem.attr('contenteditable', false)
    // 开启编辑功能
    // editor.$textElem.attr('contenteditable', true)

    $("#btn").click(function () {
        // 读取 html
        alert(editor.txt.html());
    })
</script>
</html>
